from typing import Optional, Dict, Any, List
from pydantic import BaseModel, Field
from datetime import datetime


class DetectionTargetBase(BaseModel):
    """检测目标基础模型"""
    name: str = Field(..., min_length=1, max_length=200, description="目标名称")
    description: Optional[str] = Field(None, description="目标描述")
    target_type: str = Field(..., description="目标类型")
    properties: Optional[Dict[str, Any]] = Field(None, description="目标属性")
    is_active: bool = Field(True, description="是否激活")


class DetectionTargetCreate(DetectionTargetBase):
    """创建检测目标请求模型"""
    pass


class DetectionTargetUpdate(BaseModel):
    """更新检测目标请求模型"""
    name: Optional[str] = Field(None, min_length=1, max_length=200, description="目标名称")
    description: Optional[str] = Field(None, description="目标描述")
    target_type: Optional[str] = Field(None, description="目标类型")
    properties: Optional[Dict[str, Any]] = Field(None, description="目标属性")
    is_active: Optional[bool] = Field(None, description="是否激活")


class DetectionTargetSchema(DetectionTargetBase):
    """检测目标响应模型"""
    id: int = Field(..., description="检测目标ID")
    created_at: datetime = Field(..., description="创建时间")
    updated_at: datetime = Field(..., description="更新时间")
    
    class Config:
        from_attributes = True


class DetectionTargetList(BaseModel):
    """检测目标列表响应模型"""
    items: List[DetectionTargetSchema] = Field(..., description="检测目标列表")
    total: int = Field(..., description="总数")
    page: int = Field(..., description="当前页码")
    page_size: int = Field(..., description="每页大小")